//
//  RenterOrdersViewController.m
//  UcarTest
//
//  Created by 陈曦 on 16/3/13.
//  Copyright © 2016年 chenxi. All rights reserved.
//

#import "RenterOrdersViewController.h"
#import "Define.h"
#import "MainPageViewController.h"
#import "SegmentTapView.h"
#import "FlipTableView.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"
#import "ForthViewController.h"
#import "RenterOrdersDetailsViewController.h"
#import "PaymentViewController.h"
#import "PayForDepositViewController.h"


@interface RenterOrdersViewController ()<SegmentTapViewDelegate,FlipTableViewDelegate>
@property (nonatomic, strong)SegmentTapView *segment;

@property (nonatomic, strong)FlipTableView *flipView;

@property (strong, nonatomic) NSMutableArray *controllsArray;

@end

@implementation RenterOrdersViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //导航条
    [self navigationItemSet];
    
    //添加选择条
    [self initSegment];
    
    [self initFlipTableView];

    
    
    
}

#pragma mark segment选择控制器
-(void)initSegment{
    self.segment = [[SegmentTapView alloc] initWithFrame:CGRectMake(0, 64, kScreenWidth, 45) withDataArray:[NSArray arrayWithObjects:@"全部",@"待支付",@"用车",@"已完成", nil] withFont:15];
    self.segment.delegate = self;
    [self.view addSubview:self.segment];
}

-(void)initFlipTableView{
    if (!self.controllsArray) {
        self.controllsArray = [[NSMutableArray alloc] init];
    }
    
    FirstViewController *v1 = [[FirstViewController alloc] init];
    
    v1.pushBlock = ^(NSString *orderID, NSString *order_status) {
        
        if ([order_status isEqualToString:@"0"]) {
            
            [self pushToPayView:orderID];

        } else if ([order_status isEqualToString:@"1"]){
            
            [self pushToRenterOrdersDetailsViewController:orderID];
            
        } else if ([order_status isEqualToString:@"2"]) {
            
            [self pushToDeposit:orderID];
        } else {
            
            [self pushToRenterOrdersDetailsViewController:orderID];

        }
                
    };
    //去支付租金
    v1.goToPayBlock = ^(NSString *orderID){
        
        [self pushToPayView:orderID];
    };
    
    //去支付押金
    v1.goToPayDeBlock = ^(NSString *orderID) {
        
        [self pushToDeposit:orderID];

    };
    
    //2-------------------------------------------------------------
    SecondViewController *v2 = [[SecondViewController alloc] init];
    //跳转
    v2.pushBlockTwo = ^(NSString *orderID, NSString *order_status) {
        if ([order_status isEqualToString:@"0"]) {
            
            [self pushToPayView:orderID];
            
        } else if ([order_status isEqualToString:@"1"]){
            
            [self pushToRenterOrdersDetailsViewController:orderID];
            
        } else if ([order_status isEqualToString:@"2"]) {
            
            [self pushToDeposit:orderID];
        } else {
            
            [self pushToRenterOrdersDetailsViewController:orderID];
            
        }
        
    };
    
    //去支付界面
    v2.goToPayBlockTwo = ^(NSString *orderID){
        
        [self pushToPayView:orderID];
    };

    v2.goToPayDeBlockTwo = ^(NSString *orderID) {
        
        [self pushToDeposit:orderID];
    };
    //3-------------------------------------------------------------

    ThirdViewController *v3 = [[ThirdViewController alloc] init];
    v3.pushBlockThree =  ^(NSString *orderID) {
        
        [self pushToRenterOrdersDetailsViewController:orderID];
    };
    //4------------------------------------------------------------

    ForthViewController *v4 = [[ForthViewController alloc] init];
    v4.pushBlockFour =  ^(NSString *orderID) {
        
        [self pushToRenterOrdersDetailsViewController:orderID];
    };



    [self.controllsArray addObject:v1];
    [self.controllsArray addObject:v2];
    [self.controllsArray addObject:v3];
    [self.controllsArray addObject:v4];
    
    self.flipView = [[FlipTableView alloc] initWithFrame:CGRectMake(0, 110, kScreenWidth, self.view.frame.size.height - 110) withArray:_controllsArray];
    self.flipView.delegate = self;
    [self.view addSubview:self.flipView];
}
#pragma mark -------- select Index
-(void)selectedIndex:(NSInteger)index
{
    [self.flipView selectIndex:index];
    
}
-(void)scrollChangeToIndex:(NSInteger)index
{
    [self.segment selectIndex:index];
}


#pragma mark 跳转到支付租金界面
- (void) pushToPayView:(NSString *)orderID {
    
    PaymentViewController *paymentVC = [[PaymentViewController alloc] init];
    
    paymentVC.orderID = orderID;
    
    [self.navigationController pushViewController:paymentVC animated:nil];
    
}

#pragma mark 跳转到支付押金页面
- (void) pushToDeposit:(NSString *)orderID {
    
    PayForDepositViewController *payDepositVC = [[PayForDepositViewController alloc] init];
    payDepositVC.orderID = orderID  ;
    
    [self.navigationController pushViewController:payDepositVC animated:nil];
    
}

#pragma mark 调到租客订单详情界面
- (void) pushToRenterOrdersDetailsViewController:(NSString *) orderSnID{
   
    RenterOrdersDetailsViewController *renterVC = [[RenterOrdersDetailsViewController alloc] init];
    renterVC.id = orderSnID;
    
    [self.navigationController pushViewController:renterVC animated:nil];
    
}


//导航条设置
- (void) navigationItemSet {
    self.navigationController.navigationBarHidden = NO;
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.font = [UIFont boldSystemFontOfSize:18];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = @"租客订单";
    self.navigationItem.titleView = titleLabel;
    self.navigationController.navigationBar.barTintColor = mainColor;
    self.view.backgroundColor = backgroundMainColor;
    
    
    //重定义返回键
    UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom];
    back.frame = CGRectMake(0, 0, 22, 22);
    [back setImage:[UIImage imageNamed:@"iconfont-fanhui-white"] forState:UIControlStateNormal];
    [back addTarget:self action:@selector(backTpMainView) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backBar = [[UIBarButtonItem alloc] initWithCustomView:back];
    self.navigationItem.leftBarButtonItem = backBar;

}

//返回主页
- (void)backTpMainView{
    
    MainPageViewController *mainVC = [[MainPageViewController alloc] init];
    
    [self.navigationController pushViewController:mainVC animated:nil];
    
    
}
@end
